/*
 * @lc app=leetcode.cn id=816 lang=golang
 *
 * [816] 模糊坐标
 */
package Solutions

import "fmt"

// @lc code=start
func ambiguousCoordinates(ss string) []string {
	var f = func(s string) []string {
		if len(s) == 1 {
			return []string{s}
		}
		//跳过前缀零
		prefixZeroCount := 0
		for i := 0; i < len(s); i++ {
			if s[i] == '0' {
				prefixZeroCount++
			} else {
				break
			}
		}
		suffixZeroCount := 0
		for i := len(s) - 1; i >= 0; i-- {
			if s[i] == '0' {
				suffixZeroCount++
			} else {
				break
			}
		}
		if suffixZeroCount > 0 && prefixZeroCount > 0 {
			return []string{}
		}
		if prefixZeroCount > 0 {
			return []string{"0." + s[1:]}
		}
		if suffixZeroCount > 0 {
			return []string{s}
		}
		tmpArr := make([]string, 0, len(s))
		right := len(s) - suffixZeroCount
		//[left,right)
		tmpArr = append(tmpArr, s)
		for i := 1; i < right; i++ {
			tmpArr = append(tmpArr, s[:i]+"."+s[i:])
		}
		return tmpArr
	}
	s := ss[1 : len(ss)-1]
	ans := make([]string, 0, 8)
	for i := 1; i < len(s); i++ {
		left := f(s[:i])
		right := f(s[i:])
		for _, v := range left {
			for _, vv := range right {
				ans = append(ans, fmt.Sprintf("(%s, %s)", v, vv))
			}
		}
	}
	return ans
}

// @lc code=end
